﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>消息发布</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <link rel="stylesheet" href="../../../lib/layui/css/layui.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
</head>

<body>
    <div class="weadmin-body">
        <form class="layui-form">
            <!--<div class="layui-form-item">
                <label for="moddesc" class="layui-form-label">
                    <span class="we-red">*</span>推送部门
                </label>

                <div class="layui-input-inline">
                    <select id="DepID" name="DepID" autocomplete="off" class="valid"></select>
                </div>
            </div>-->

            <div class="layui-form-item">
                <div class="layui-form-label">下发部门</div>
                <div class="layui-input-block">
                    <input type="text" autocomplete="off" readonly="" id="selectDatas" name="selectDatas" placeholder="请选择" class="layui-input" />
                    <div class="eleTree" lay-filter="data5"></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label"> <span class="we-red">*</span>起始日期</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="startdate" type="text" lay-verify="required" placeholder="yyyy-MM-dd">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label"> <span class="we-red">*</span>结束日期</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="enddate" type="text" lay-verify="required" placeholder="yyyy-MM-dd">
                    </div>
                </div>
                <div class="layui-inline">
                    <label for="MsgType" class="layui-form-label">
                        消息类型
                    </label>
                    <div class="layui-input-inline">
                        <select id="MsgType" name="MsgType" class="valid">
                            <option value=""></option>
                            <option value="通知公告">通知公告</option>
                            <option value="一般消息">一般消息</option>
                            <option value="特定消息">特定消息</option>
                        </select>
                    </div>

                </div>
            </div>

            <div class="layui-form-item">
                <label for="modid" class="layui-form-label">
                    <span class="we-red">*</span>消息标题
                </label>
                <div class="layui-input-block">
                    <input name="username" id="msgtitle" class="layui-input" type="text" placeholder="请输入标题" autocomplete="off" lay-verify="required">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="modname" class="layui-form-label">
                    <span class="we-red">*</span>消息内容
                </label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea" id="msgcontent" placeholder="请输入内容" lay-verify="required"></textarea>
                </div>

            </div>

            <div class="layui-form-item">
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">发布推送</button>
            </div>
        </form>
    </div>
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../static/js/common.js" charset="utf-8"></script>
    <script>
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //常规用法
            laydate.render({
                elem: '#test1'
            });

            //国际版
            laydate.render({
                elem: '#test1-1'
                , lang: 'en'
            });

            //年选择器
            laydate.render({
                elem: '#test2'
                , type: 'year'
            });

            //年月选择器
            laydate.render({
                elem: '#test3'
                , type: 'month'
            });

            //时间选择器
            laydate.render({
                elem: '#test4'
                , type: 'time'
            });

            //日期时间选择器
            laydate.render({
                elem: '#startdate'
                , type: 'date'
            });

            //日期时间选择器
            laydate.render({
                elem: '#enddate'
                , type: 'date'
            });
            //日期范围
            laydate.render({
                elem: '#test6'
                , range: true
            });

            //年范围
            laydate.render({
                elem: '#test7'
                , type: 'year'
                , range: true
            });

            //年月范围
            laydate.render({
                elem: '#test8'
                , type: 'month'
                , range: true
            });

            //时间范围
            laydate.render({
                elem: '#test9'
                , type: 'time'
                , range: true
            });

            //日期时间范围
            laydate.render({
                elem: '#test10'
                , type: 'datetime'
                , range: true
            });

            //自定义格式
            laydate.render({
                elem: '#test11'
                , format: 'yyyy年MM月dd日'
            });
            laydate.render({
                elem: '#test12'
                , format: 'dd/MM/yyyy'
            });
            laydate.render({
                elem: '#test13'
                , format: 'yyyyMMdd'
            });
            laydate.render({
                elem: '#test14'
                , type: 'time'
                , format: 'H点m分'
            });
            laydate.render({
                elem: '#test15'
                , type: 'month'
                , range: '~'
                , format: 'yyyy-MM'
            });
            laydate.render({
                elem: '#test16'
                , type: 'datetime'
                , range: '到'
                , format: 'yyyy年M月d日H时m分s秒'
            });

            //开启公历节日
            laydate.render({
                elem: '#test17'
                , calendar: true
            });

            //自定义重要日
            laydate.render({
                elem: '#test18'
                , mark: {
                    '0-10-14': '生日'
                    , '0-12-31': '跨年' //每年的日期
                    , '0-0-10': '工资' //每月某天
                    , '0-0-15': '月中'
                    , '2017-8-15': '' //如果为空字符，则默认显示数字+徽章
                    , '2099-10-14': '呵呵'
                }
                , done: function (value, date) {
                    if (date.year === 2017 && date.month === 8 && date.date === 15) { //点击2017年8月15日，弹出提示语
                        layer.msg('这一天是：中国人民抗日战争胜利72周年');
                    }
                }
            });

            //限定可选日期
            var ins22 = laydate.render({
                elem: '#test-limit1'
                , min: '2016-10-14'
                , max: '2080-10-14'
                , ready: function () {
                    ins22.hint('日期可选值设定在 <br> 2016-10-14 到 2080-10-14');
                }
            });

            //前后若干天可选，这里以7天为例
            laydate.render({
                elem: '#test-limit2'
                , min: -7
                , max: 7
            });

            //限定可选时间
            laydate.render({
                elem: '#test-limit3'
                , type: 'time'
                , min: '09:30:00'
                , max: '17:30:00'
                , btns: ['clear', 'confirm']
            });

            //同时绑定多个
            lay('.test-item').each(function () {
                laydate.render({
                    elem: this
                    , trigger: 'click'
                });
            });

            //初始赋值
            laydate.render({
                elem: '#test19'
                , value: '1989-10-14'
                , isInitValue: true
            });

            //选中后的回调
            laydate.render({
                elem: '#test20'
                , done: function (value, date) {
                    layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
                }
            });

            //日期切换的回调
            laydate.render({
                elem: '#test21'
                , change: function (value, date) {
                    layer.msg('你选择的日期是：' + value + '<br><br>获得的对象是' + JSON.stringify(date));
                }
            });
            //不出现底部栏
            laydate.render({
                elem: '#test22'
                , showBottom: false
            });

            //只出现确定按钮
            laydate.render({
                elem: '#test23'
                , btns: ['confirm']
            });

            //自定义事件
            laydate.render({
                elem: '#test24'
                , trigger: 'mousedown'
            });

            //点我触发
            laydate.render({
                elem: '#test25'
                , eventElem: '#test25-1'
                , trigger: 'click'
            });

            //双击我触发
            lay('#test26-1').on('dblclick', function () {
                laydate.render({
                    elem: '#test26'
                    , show: true
                    , closeStop: '#test26-1'
                });
            });

            //日期只读
            laydate.render({
                elem: '#test27'
                , trigger: 'click'
            });

            //非input元素
            laydate.render({
                elem: '#test28'
            });

            //墨绿主题
            laydate.render({
                elem: '#test29'
                , theme: 'molv'
            });

            //自定义颜色
            laydate.render({
                elem: '#test30'
                , theme: '#393D49'
            });

            //格子主题
            laydate.render({
                elem: '#test31'
                , theme: 'grid'
            });


            //直接嵌套显示
            laydate.render({
                elem: '#test-n1'
                , position: 'static'
            });
            laydate.render({
                elem: '#test-n2'
                , position: 'static'
                , lang: 'en'
            });
            laydate.render({
                elem: '#test-n3'
                , type: 'month'
                , position: 'static'
            });
            laydate.render({
                elem: '#test-n4'
                , type: 'time'
                , position: 'static'
            });
        });
    </script>

    <script type="text/javascript">

        var currentInfoDeptId = 0;//当前选中信息的 部门id
        var selectobjs = [];//
        //加载 [赋值]获取数据  (部门相关数据)
        var dataSelect = [];
        var temp_deptId_List = [];//列表中选择信息时   使用字段中的内容=>为其赋值,可以使用此字段保存
        var dataCurent = [];

        layui.extend({
            selectM: '../../../lib/layui_extends/selectM'
        });
        layui.use(['form', 'layer', 'jquery', 'selectM','tree'], function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer;
            var eleTree = layui.tree;
            $.support.cors = true;
            $.ajaxSetup({
                cache: false,
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
            })
            $.ajax({
                url: ApiUrl + "Dep/Sel",
                type: 'post',
                success: function (data) {
                    if (data.StatusCode == 200) {
                        $(data.Data).each(function (index, item) {
                            $("#DepID").append("<option value='" + item.DepID + "'>" + item.DepName + "</option>");
                        });
                        form.render();
                    }
                }
            });


            //获取当前 部门级别id,部门id
            $.ajax({
                url: ApiUrl + "Dep/DeptLevel",//SelTree
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        currentDeptLevelId = data.Data.currentDeptLevelId;
                        cuurentDeptId = data.Data.cuurentDeptId;
                        GetDept(cuurentDeptId);
                    }
                    else if (data.StatusCode == 403) {
                        layer.alert(data.Info, function () {
                            top.location.href = "http://" + top.location.host + "/login.html";
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                }
            });
            //获取下级部门列表树
            function GetDept(deptid) {
                var r = 0;
                $.ajax({
                    url: ApiUrl + "Dep/SelNextTree",//SelTree
                    type: 'post',
                    async: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { DepID: deptid },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            dataSelect = data.Data;
                            loadTree();
                            r = 1;
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                return r;
            }
            var tempList = [];
            function SetTextFromTree(v) {
                for (var i = 0; i < v.length; i++) {
                    var c = v[i];
                    tempList.push({ id: c.id, title: c.title });
                    temp_deptId_List.push(c.id);
                    var a = $("#selectDatas").val();
                    if (a != "") { a += ","; }
                    $("#selectDatas").val(a + c.title);
                    if (c.children != undefined) {
                        if (c.children.length > 0) {
                            SetTextFromTree(c.children);
                        }
                    }
                }
            }

            function setTree()//选择信息列表中 信息时 调用该方法  并为temp_deptId_List赋值
            {
                eleTree.setChecked('eleTreeid', temp_deptId_List);
            }

            var el_tree;
            $("#selectDatas").on("click", function (e) {
                e.stopPropagation();
                loadTree();
                $(".eleTree").toggle();
            });

            function loadTree() {
                el_tree =
                    eleTree.render({
                        elem: '.eleTree',
                        id: 'eleTreeid',
                        data: dataSelect,
                        defaultExpandAll: false,
                        expandOnClickNode: false,
                        highlightCurrent: true
                        , checkStrictly: true
                        , showCheckbox: true
                        , oncheck: function (obj) {
                            $("#selectDatas").val("");
                            temp_deptId_List = [];
                            tempList = [];
                            SetTextFromTree(el_tree.getChecked());
                        }
                    });
            }
            //监听提交
            form.on('submit(add)', function (data) {
                var postdata = {
                    'DepID': temp_deptId_List.toString(),
                    'MsgStartTime': $("#startdate").val(),
                    'MsgEndTime': $("#enddate").val(),
                    'MsgTitle': $("#msgtitle").val(),
                    'MsgContent': $("#msgcontent").val(),
                    'MsgType': $("#MsgType").val()
                };
                //发异步，把数据提交给后台
                $.post(ApiUrl + 'MessageInfo/Add', postdata, function (data) {
                    if (data.StatusCode == 200) {
                        layer.msg("消息添加成功！");
                        parent.layer.closeAll();
                    }
                    else {
                        layer.msg(data.Info);
                    }
                })
                return false;
            });
        });
    </script>
</body>

</html>